#include<bits/stdc++.h>
using namespace std;
int main()
{
	int leap,n,i,y,m,d;
	cin>>n;
	while(n--)
	{
		int num=0;
		int day[100]={0,31,28,31,30,31,30,31,31,30,31,30,31};
		cin>>y>>m>>d;
		leap=y%4==0&&y%100!=0||y%400==0;
		day[2]=day[2]+leap;
		for(i=1;i<m;i++)
		num+=day[i];
		cout<<num+d<<endl;
	}
    return 0;
}
